
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings
from apps.oauth.constants import OPENID_TOKEN_EXPIRES_TIME
import logging
logger = logging.getLogger('django')
def generic_openid_tocken(openid):

    s = Serializer(settings.SECRET_KEY, OPENID_TOKEN_EXPIRES_TIME)

    data = {'openid': openid}

    token = s.dumps(data)
    # b'eyJleHAiOjE1NTc5MjU3MjksImFsZyI6IkhTNTEyIiwiaWF0IjoxNTU3OTI1NDI5fQ.eyJvcGVuaWQiOiJhYmNkZSJ9.AmrS99mLFuZzjHd3pfrKdrYG2jsbLkkGKDb-Ua4iD3TrEX7SJjSUHDKsHFBduMzUVYxeTtjANxEz9kkIwt1z0w'
    return token.decode()
from itsdangerous import SignatureExpired,BadData
def check_openid_tocken(token):
    s = Serializer(settings.SECRET_KEY, OPENID_TOKEN_EXPIRES_TIME)
    try:
        result=s.loads(token)
    except BadData as e:

        logger.error(e)
        return None
    return result.get('openid')



